--[[
 -- *名称:BombTypeAnalyzer
 -- *描述:炸弹分析器
 -- *版权:Copyright © 2016-2018 深圳市三只小熊科技有限公司 版权所有
 -- *作者:Administrator
 -- *创建日期:2017-11-08
 -- *修改日期:2017-11-08
 ]]
local DdzSuitAnalyzer = require(basePath.."suit/ddzsuitanalyzer");
local BombTypeAnalyzer = pokercore.class(DdzSuitAnalyzer,false);
local BombAnalysisResult = require(basePath.."suit/bomb/bombanalysisresult");
-- 关键数量
local TUPLE_SIZE = 3;
BombTypeAnalyzer.TUPLE_SIZE = 3 ;
function BombTypeAnalyzer:getSuitType(  )
	return DdzCardTypes.BOMB;
end

--@Override
function BombTypeAnalyzer:getSuitResult()
	 local result = pokercore.new(BombAnalysisResult);
     --print("getSuitResult->",result) ;
	 result:setType(self:getSuitType());
	 return result;
	--return SuperBombTypeAnalyzer.super.getSuitResult(self);
end

function BombTypeAnalyzer:doCheckRule( cards, term, result )
	if result:getCardNum() == TUPLE_SIZE then 
		if result:getLaziCardNum() == 0 then -- 没有癞子，都是癞子
			return #result:getAllValueCounter():getValuesInCount(TUPLE_SIZE) > 0;
		else 
			return false; -- 癞子的情况
		end
	else 
		return false;
	end
end

function BombTypeAnalyzer:doAnalysizeLaizi( cards, term, onlyMaxValue )
	local cardsResult = {};
	local cardsCopy = cards:clone();	
	self:analysize(cardsCopy,term);
	table.insert(cardsResult,cardsCopy);
	return cardsResult;
end

--@Override
function BombTypeAnalyzer:containsPossibleCards(handCards, term) 
	local result = handCards:getResult();
	if (result:getCardNum() >= TUPLE_SIZE) then
		return #result:getAllValueCounter():getValuesInCount(TUPLE_SIZE) > 0 or 
			#result:getAllValueCounter():getValuesInCount(TUPLE_SIZE + 1) > 0;
	else 
		return false;
	end
end


--@Override
function BombTypeAnalyzer:doListPossibleCards(handCards, term) 
	local cardsResult = {};
	local result = handCards:getResult();
	local noneLaiziCardList = handCards:subList(1, result:getNoneCardNum());
	local noneLaiziCards = DdzTypeUtil.createCardsCopy(noneLaiziCardList);
	noneLaiziCards:setResult(handCards:getResult():clone());
	
	--// 非癞子部分寻找炸弹
	local count_4_cardsList = DdzTypeUtil.selectTupleCountCards(noneLaiziCards, TUPLE_SIZE);
	for _,cardsCopy in ipairs(count_4_cardsList) do
		if (self:match(cardsCopy, term)) then
			self:analysize(cardsCopy, term);
			table.insert(cardsResult,cardsCopy);
		end
	end
	if (result:getLaziCardNum() >= TUPLE_SIZE) then -- // 考虑癞子
		local laiziCardList = handCards:subList(result.getNoneCardNum()+1, result.getCardNum());
		local laiziCards = DdzTypeUtil.createCardsCopy(laiziCardList);
		laiziCards:setResult(handCards:getResult():clone());
		--// 癞子部分寻找炸弹
		local count_4_laiziCardsList = DdzTypeUtil.selectTupleCountCards(laiziCards, TUPLE_SIZE);
		for _,cardsCopy in ipairs(count_4_laiziCardsList) do
			if (self:match(cardsCopy, term)) then
				self:analysize(cardsCopy, term);
				table.insert(cardsResult,cardsCopy);
			end
		end
	end
	return cardsResult;
end

return BombTypeAnalyzer;

